package com.xin.components.base
{
	import flash.events.MouseEvent;
	/**
	 * 多选按钮基类
	 */
	public class CheckBoxBase extends LiteSprite
	{
		protected var _selected:Boolean = false;
		
		/**
		 * 构造方法
		 */		
		public function CheckBoxBase(w:int, h:int, clickHandler:Function = null)
		{
			if (clickHandler != null)
			{
				addEventListener(MouseEvent.CLICK, clickHandler);
			}
			
			super(w, h);
		}
		
		protected override function init():void
		{
			super.init();
			
			addEventListener(MouseEvent.CLICK, onClick, false, 1);
			
			buttonMode = useHandCursor = true;
			mouseChildren = false;
		}
		
		/**
		 * 切换到选择状态
		 */		
		protected function goSelect():void{};
		
		/**
		 * 切换到未选择状态
		 */		
		protected function goUnselect():void{};
		
		/////////////////////////////////////////////
		// 事件处理
		/////////////////////////////////////////////
		protected function onClick(e:MouseEvent):void
		{
			this.selected = !_selected;
		}
		
		/////////////////////////////////////////////
		// Getter & Setter
		/////////////////////////////////////////////
		
		/**
		 * 设置选择状态
		 */		
		public function set selected(value:Boolean):void
		{
			_selected = value;
			
			if (_selected == true)
			{
				goSelect();
			}
			else
			{
				goUnselect();
			}
		}
		public function get selected():Boolean
		{
			return _selected;
		}
		
		/**
		 * 不管组件是否可用, 子对象总是不可接受鼠标相应
		 */		
		public override function set enabled(value:Boolean):void
		{
			super.enabled = value;
			mouseChildren = false;
		}
	}
}